#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int data;
    struct node* next;
}linkstack_t;

linkstack_t *linkstack_init(void) {
    linkstack_t *h = (linkstack_t*)malloc(sizeof(linkstack_t));
    h->next = NULL;
    h->data = 0;
    return h;
}

int linkstack_isempty(linkstack_t* s) {
    return (s->next == NULL);
}

int linkstack_push(linkstack_t* s,int value) {
    linkstack_t * p = (linkstack_t*)malloc(sizeof(linkstack_t));
    p->data = value;
    p->next = s->next;
    s->next = p;
    return 0;
}

int linkstack_pop(linkstack_t* s,int * pvalue) {
    linkstack_t * p = s->next;
    if(linkstack_isempty(s)) {
        printf("kong");
        return -1;
    }
    *pvalue = p->data;
    s->next = p->next;
    free(p);
    return 0;
}

int main() {
    linkstack_t *s = linkstack_init();
    printf("ru:");
    for(int i = 0; i <= 32; i++) {
        if(linkstack_push(s,i+1)>=0) {
            printf("%d ",i+1);
        }
    }
    printf("\n");
    printf("chu:");
    for(int i = 0; i <= 32; i++) {
        int value;
        if(linkstack_pop(s,&value)>=0) {
            printf("%d ",value);
        }
    }
    printf("\n");
    return 0;
}